<?php

	/**
	* 
	*/
	class Activity_model extends CI_Model
	{
		
		function __construct()
		{
			$this->load->database();
		}

		/*根据活动id将活动相关信息取出,没有传入id则取出全部信息*/
		function getActInfo($iActId = FALSE)
		{
			//如果没有活动id
		    if ($iActId === FALSE)
		    {
		        $query = $this->db->get('activity');
		        return $query->result_array();
		    }
		    //如果有活动id
		    $query = $this->db->get_where('activity', array('iActId' => $iActId));
		    return $query->row_array();
		}
		/*根据用户id取出其所创建的活动信息*/
		function getActInfoByMaster($vcUserId)
		{
			$query = $this->db->get_where('activity', array('vcUserId' => $vcUserId));
			return $query->result_array();
		}
		/*根据用户id获取活动数量,没有传入id则获取全部数量*/
 		function getActInfoNum($vcUserId=FALSE)
 		{
			//如果没有用户id
		    if ($vcUserId === FALSE)
		    {
		        $query = $this->db->get('activity');
 				return $query->num_rows();
		    }
		    //如果有用户id
		    $query = $this->db->get_where('activity', array('vcUserId' => $vcUserId));
 			return $query->num_rows();
 		}
		/*增加活动信息*/
		function insertActInfo($data)
 		{
 			//var_dump($data);
 			return $this->db->insert('activity',$data);
 		}
 		/*根据活动id删除活动信息*/
 		function deleteActInfo($iActId)
 		{
 			$this->db->delete('activity',array('iActId'=>$iActId));
 		}
 		/*根据活动id修改信息*/
 		function updateActInfo($iActId,$data)
 		{
 			$this->db->where('iActId',$iActId);
 			return $this->db->update('activity',$data);
 		}
 		/*删除用户*/
 		function deleteUser($userId)
 		{
 			$this->db->dalete('login',array('userId' => $userId));/*删除用户账号和密码*/
 			$this->db->delete('activity',array('vcUserId' => $$userId));/*删除用户创建的活动*/
 		}
 		/*根据用户id获取创建活动数，没有则获取全部活动数*/
 		function getActNum($vcUserId = FALSE)
 		{
 			if($vcUserId === FALSE){
	 			$query = $this->db->query('SELECT * FROM activity');
	 			return $query->num_rows();
	 		}
	 		$query = $this->db->get('activity', array('vcUserId' => $vcUserId));
	 		return $query->num_rows();
 		}
 		/*获取用户总数*/
 		function getUserNum()
 		{
 			$query = $this->db->query('SELECT * FROM login');
 			return $query->num_rows();
 		}
 		/*用来从活动跳转到问卷*/
 		function maxActId()
 		{
 			$this->db->select_max('iActId');
 			$query = $this->db->get('activity');
 			return $query->row_array();
 		}
	}